package com.hrt.datasender.dataschedule;

import com.btcode.common.MyLog;
import com.btcode.log.ILog;
import com.btcode.schedule.ScheduleManager;

public class DataSchedulerMain {

    private static ILog log;

    public static void start(String appBasePath) {

        log = MyLog.getInstance().getLogger(DataSchedulerMain.class);

        try {

            /**
             * 负责把数据发送出去
             */
            ScheduleManager.getInstance().addJob(DataStorageScheduler.class, "0/30 * * * * ?");
            /**
             * 负责发送心跳
             */
            ScheduleManager.getInstance().addJob(HeatbeatScheduler.class, "0/10 * * * * ?");
            /**
             * 负责清理BD_SOURCE表数据
             */
            ScheduleManager.getInstance().addJob(DataClearScheduler.class, "0 30 3 * * ?");
            /**
             * 清理BD_S60_RT表数据
             */
            ScheduleManager.getInstance().addJob(DataClearRtScheduler.class, "0 59 23 * * ?");
            /**
             * 清理BD_S10_MINUTES表数据
             */
            ScheduleManager.getInstance().addJob(DataClearMinutesScheduler.class, "10 59 23 * * ?");
            /**
             * 清理BD_S1_HOUR表数据
             */
            ScheduleManager.getInstance().addJob(DataClearHourScheduler.class, "20 59 23 * * ?");
            /**
             * 刷新onenet注册码时间
             */
            ScheduleManager.getInstance().addJob(OneNetScheduler.class, "0 0 0/6 * * ?");
            /**
             * 压缩数据库 VACUUM命令需要在没有sql活动的情况下执行，故采用Auto-VACUUM方式，不采用定时任务
             * sqlite执行 PRAGMA auto_vacuum = FULL;
             * 效果有待观察
             */
            //ScheduleManager.getInstance().addJob(DataCompressScheduler.class, "0 12 23 * * ?");
            /**
             * 配置存储上传
             */
            ScheduleManager.getInstance().addJob(ConfigStorageUploadScheduler.class, "30 30 23 * * ?");


            // DeleteLogScheduler.logBasePath = appBasePath + "/log";
            DeleteLogScheduler.logBasePath = appBasePath;

            /**
             * 负责删除日志文件
             */
            ScheduleManager.getInstance().addJob(DeleteLogScheduler.class, "0 0 0/6 * * ?");

            /**
             * 负责更新校准时间List
             */
            ScheduleManager.getInstance().addJob(UpdateCalTimeScheduler.class, "30 30 0/1 * * ?");

            /**
             * 负责处理接收到的数据
             */
            DataReceiveScheduler.start();

            /**
             * 负责数据日志归档
             */
            ScheduleManager.getInstance().addJob(PackLogScheduler.class, "30 30 0/6 * * ?");

            /**
             * 负责生成PLC报警
             */
//            ScheduleManager.getInstance().addJob(PlcAlarmScheduler.class, "30 * * * * ?");

            log.info("启动调度模块成功");
        }
        catch (Exception e) {
            log.error("启动调度模块出错", e);
        }

    }

}
